package sailingTest;

import java.util.HashMap;
import java.util.Map;

import sailing.dao.CustomerDao;
import sailing.dao.impl.CustomerDaoImpl;
import sailing.db.DataSourceManagerImpl;
import sailing.entity.AccountingSubject;
import sailing.entity.BankAccount;
import sailing.entity.BankDepositsAccount;
import sailing.entity.BankName;
import sailing.entity.BankStatement;
import sailing.entity.BillsDetail;
import sailing.entity.CashAccount;
import sailing.entity.CashVoucher;
import sailing.entity.Cashier;
import sailing.entity.Customer;
import sailing.entity.LoanAccount;
import sailing.entity.ReceivableDetail;
import sailing.entity.RunningAccount;
import sailing.managers.CustomerManager;
import sailing.managers.impl.CustomerManagerImpl;
import cjlite.IocConfigurator;
import cjlite.IocModule;
import cjlite.dao.DaoSqlSupportManager;
import cjlite.dao.DataSourceManager;
import cjlite.dao.core.DaoSqlSupportManagerImpl;
import cjlite.dao.utils.DB;
import cjlite.dao.utils.DdlUtils;
import cjlite.logger.Logger;
import cjlite.logger.Logger.LogConfig;
import cjlite.utils.RandomUtils;

public class Main {

	// static IOC ioc = IocBuilder.createIOC(getIocModule());

	/**
	 * @param args
	 */
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Map<String, String> configMap = new HashMap<String, String>() {
			{
				put("Logger.level", "All");
			}
		};
		Logger.setConfig(LogConfig.fromMap(configMap));

		DaoSqlSupportManager dssmgr = new DaoSqlSupportManagerImpl();
		Customer c = new Customer();
		c.setId(RandomUtils.randomString16());
		c.setName("BMW");
		c.setCreateTime(System.currentTimeMillis());

		try {
			DdlUtils.use(DB.H2);
			// no using H2 database dialect

			DdlUtils.dropTableCommandCreation(true);

			/*System.out.println(DdlUtils.createDDL(CashAccount.class, Cashier.class, AccountingSubject.class,
					BankDepositsAccount.class, Customer.class, BankName.class, BankAccount.class));
			 System.out.println(DdlUtils.createDDL(Cashier.class,true));
			 System.out.println(DdlUtils.createDDL(AccountingSubject.class,true));
			 System.out.println(DdlUtils.createDDL(BankDepositsAccount.class,true));
			 System.out.println(DdlUtils.createDDL(CashAccount.class,true));
			 System.out.println(DdlUtils.createDDL(Customer.class,true));
			 System.out.println(DdlUtils.createDDL(CashVoucher.class,true));
			 System.out.println(DdlUtils.createDDL(ReceivableDetail.class,true));
			 System.out.println(DdlUtils.createDDL(LoanAccount.class,true));
			 System.out.println(DdlUtils.createDDL(RunningAccount.class,true));
			 System.out.println(DdlUtils.createDDL(BankName.class,true));
			 System.out.println(DdlUtils.createDDL(BankAccount.class,true));
			 System.out.println(DdlUtils.createDDL(AccountingSubject.class,true));
			 System.out.println(DdlUtils.createDDL(CashAccount.class, true));*/
			 System.out.println(DdlUtils.createDDL(BankStatement.class, true));
			 System.out.println(DdlUtils.createDDL(BillsDetail.class, true)); 

			// DaoSqlSupport BankAcountdss = dssmgr.getByClass(BankAcount.class);
			// //System.out.println(BankAcountdss.getCreateDDL(true));
			// DaoSqlSupport dss = dssmgr.getByClass(c.getClass());
			// //System.out.println(dss.getCreateDDL(true));
			//
			// System.out.println(dss.getInsertSql(c));
			// System.out.println(dss.getUpdateSql(c));
			// System.out.println(dss.getDeleteSql(c));
			// System.out.println(dss.getSelectAllSql());
			// System.out.println(dss.getSelectSqlById(c.getId()));

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	protected static IocModule getIocModule() {
		return new IocModule() {

			@Override
			public void configure(IocConfigurator configurator) {
				configurator.addBean(CustomerManager.class).to(CustomerManagerImpl.class).asSingleton();
				configurator.addBean(DataSourceManager.class).to(DataSourceManagerImpl.class).asEagerSingleton();
				configurator.addBean(DaoSqlSupportManager.class).to(DaoSqlSupportManagerImpl.class).asEagerSingleton();

				configurator.addBean(CustomerDao.class).to(CustomerDaoImpl.class).asSingleton();

			}
		};
	}
}
